from enum import Enum


class TokenType(Enum):
    # 关键字 (种别码 1xx)
    KEYWORD_SELECT = 101
    KEYWORD_FROM = 102
    KEYWORD_WHERE = 103
    KEYWORD_CREATE = 104
    KEYWORD_TABLE = 105
    KEYWORD_INSERT = 106
    KEYWORD_INTO = 107
    KEYWORD_VALUES = 108
    KEYWORD_DELETE = 109
    KEYWORD_UPDATE = 110
    KEYWORD_SET = 111

    KEYWORD_INTEGER = 112
    KEYWORD_VARCHAR = 113
    KEYWORD_FLOAT=114
    KEYWORD_BOOLEAN=115
    KEYWORD_DATE=116

    KEYWORD_NULL = 117
    KEYWORD_IS=118
    KEYWORD_IN=119


    # 标识符 (种别码 2)
    IDENTIFIER = 2

    # 常量 (种别码 3xx)
    CONSTANT_NUMBER = 301
    CONSTANT_STRING = 302

    # 运算符 (种别码 4xx)
    OPERATOR_PLUS = 401  # +
    OPERATOR_MINUS = 402  # -
    OPERATOR_MUL = 403  # *
    OPERATOR_DIV = 404  # /
    OPERATOR_MOD = 405 # %
    OPERATOR_EQ = 406  # =
    OPERATOR_GT = 407  # >
    OPERATOR_NE = 408  # !=
    OPERATOR_GE = 409  # >=
    OPERATOR_LT = 410  # <
    OPERATOR_LE = 411  # <=
    OPERATOR_AND = 412  # AND
    OPERATOR_OR = 413  # OR
    OPERATOR_NOT = 414  # NOT

    # 界符 (种别码 5xx)
    DELIMITER_COMMA = 501  # ,
    DELIMITER_SEMICOLON = 502  # ;
    DELIMITER_LPAREN = 503  # (
    DELIMITER_RPAREN = 504  # )
    DELIMITER_PERIOD = 505  # .
    DELIMITER_LBRACE=506 # {
    DELIMITER_RBRACE=507 # }

    # 结束标记 (种别码 0)
    EOF = 0


# 关键字映射字典
KEYWORDS = {
    'SELECT': TokenType.KEYWORD_SELECT,
    'FROM': TokenType.KEYWORD_FROM,
    'WHERE': TokenType.KEYWORD_WHERE,
    'CREATE': TokenType.KEYWORD_CREATE,
    'TABLE': TokenType.KEYWORD_TABLE,
    'INSERT': TokenType.KEYWORD_INSERT,
    'INTO': TokenType.KEYWORD_INTO,
    'VALUES': TokenType.KEYWORD_VALUES,
    'DELETE': TokenType.KEYWORD_DELETE,
    'UPDATE': TokenType.KEYWORD_UPDATE,
    'SET': TokenType.KEYWORD_SET,
    'AND': TokenType.OPERATOR_AND,
    'OR': TokenType.OPERATOR_OR,
    'NOT': TokenType.OPERATOR_NOT,
    'INTEGER': TokenType.KEYWORD_INTEGER,
    'VARCHAR': TokenType.KEYWORD_VARCHAR,
    'FLOAT':TokenType.KEYWORD_FLOAT,
    'BOOLEAN': TokenType.KEYWORD_BOOLEAN,
    'DATE': TokenType.KEYWORD_DATE,
    'NULL': TokenType.KEYWORD_NULL,
    'IS': TokenType.KEYWORD_IS,
    'IN': TokenType.KEYWORD_IN
}


class Token:
    """Token类，表示一个词法单元"""

    def __init__(self, token_type, value, line, column):
        self.type = token_type
        self.value = value
        self.line = line
        self.column = column

    def __str__(self):
        return f"Token({self.type.name}, '{self.value}', line={self.line}, column={self.column})"

    def __repr__(self):
        return self.__str__()